import threading
import curses
import os
from time import sleep

import function.get_user_link


class T(threading.Thread):
    def __init__(self, stream_in, stream_out, _position):
        super().__init__()
        self.stream_in = stream_in
        self.stream_out = stream_out
        self.position = _position

    def run(self):
        c = curses.initscr()

        function.get_user_link.user_more_than(50, c, self.position, self.stream_in, self.stream_out)


def main():
    """
    三个线程组
    :return:
    """
    mc = curses.initscr()
    mc.border(0)
    mc.addstr(1, 1, "now the program is running:")
    mc.refresh()

    threads = []
    for i in range(14):
        stream_in = os.path.join(os.path.dirname(__file__), 'data\\ud_ndp\\ud_ndp_%s.yaml' % str(i + 1))
        stream_out = os.path.join(os.path.dirname(__file__), 'data\\ud_mt\\ud_mt_%s.yaml' % str(i + 1))
        threads.append(T(stream_in, stream_out, i + 2))
    # threads_1 = []
    # threads_2 = []
    # threads_3 = []
    # for i in range(5):
    #     stream_in = os.path.join(os.path.dirname(__file__), 'data\\ud_ndp\\ud_ndp_%s.yaml' % str(i + 1))
    #     stream_out = os.path.join(os.path.dirname(__file__), 'data\\ud_mt\\ud_mt_%s.yaml' % str(i + 1))
    #     threads_1.append(T(stream_in, stream_out, i + 2))
    #
    # for i in range(5, 10):
    #     stream_in = os.path.join(os.path.dirname(__file__), 'data\\ud_ndp\\ud_ndp_%s.yaml' % str(i + 1))
    #     stream_out = os.path.join(os.path.dirname(__file__), 'data\\ud_mt\\ud_mt_%s.yaml' % str(i + 1))
    #     threads_2.append(T(stream_in, stream_out, i - 3))
    #
    # for i in range(10, 14):
    #     stream_in = os.path.join(os.path.dirname(__file__), 'data\\ud_ndp\\ud_ndp_%s.yaml' % str(i + 1))
    #     stream_out = os.path.join(os.path.dirname(__file__), 'data\\ud_mt\\ud_mt_%s.yaml' % str(i + 1))
    #     threads_3.append(T(stream_in, stream_out, i - 8))

    for thread in threads:
        thread.start()
        sleep(.1)

    mc.getch()
    curses.endwin()


if __name__ == "__main__":
    # print(os.path.join(os.path.dirname(__file__), 'data\\ud_ndp\\ut_ndp_%s.yaml' % str(1)))
    main()